package com.qk.service.impl;

import com.qk.mapper.BusinessMapper;
import com.qk.mapper.ClueMapper;
import com.qk.service.ReportService;
import com.qk.vo.OverviewVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Slf4j
@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private ClueMapper clueMapper;
    @Autowired
    private BusinessMapper businessMapper;
    @Autowired
    private RedisTemplate<Object, Object> redisTemplate;

    @Override
    public OverviewVo overview() {
        log.info("获取报表数据");
        Object o = redisTemplate.opsForValue().get("overview");
        if (o!=null){
            return (OverviewVo) o;
        }
        OverviewVo ov1 = clueMapper.overview();
        OverviewVo ov2 = businessMapper.overview();
        BeanUtils.copyProperties(ov2, ov1,"clueTotal","clueWaitAllot","clueWaitFollow","clueFollowing","clueFalse","clueConvertBusiness");
        redisTemplate.opsForValue().set("overview", ov1,1, TimeUnit.MINUTES);//缓存1分钟
        return ov1;
    }
}
